package com.dzz.sjgl.jpa;

import com.dzz.sjgl.entity.UserInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Date;

/**
 * @author KRIC
 */
public interface UserRepository extends JpaRepository<UserInfo, Integer>, JpaSpecificationExecutor<UserInfo>, Serializable {

    @Query(value = "select t from UserInfo t where t.login = :login ")
    UserInfo getUserByLogin(@Param("login") String login);

    @Modifying
    @Transactional
    @Query(value = "update UserInfo u set u.lastLogin = :date where u.login= :login")
    int updateLoginTime(@Param("login") String login, @Param("date") Date date);
}
